package com.ts.api.module.app.form.service.impl;

import com.gitee.apanlh.util.base.CollUtils;
import com.gitee.apanlh.util.base.Eq;
import com.ts.api.common.constant.app.AppBizCodeEnum;
import com.ts.api.common.context.ChannelContext;
import com.ts.api.module.app.form.service.AppFormService;
import com.ts.api.module.channel.dao.ChannelFormDao;
import com.ts.api.module.channel.entity.po.ChannelFormFieldPO;
import com.ts.api.module.channel.entity.po.ChannelPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
public class AppFormServiceImpl implements AppFormService {

    @Autowired
    private ChannelFormDao formFieldDao;

    @Override
    public List<ChannelFormFieldPO> listEsdForm(AppBizCodeEnum appBizCodeEnum) {
        ChannelPO channelPO = ChannelContext.get();
        List<ChannelFormFieldPO> list = formFieldDao.listByChannelId(channelPO.getId());

        // 2025-02-27 "享用米-OPPO"屏蔽掉"贷款金额"的"20万以上"
        if (Objects.equals(channelPO.getId(), 362L)) {
            list = list.stream().filter(item -> !Objects.equals(item.getFieldValueId(), 51L)).collect(Collectors.toList());
        }

        //  大额贷
        if (Eq.enums(appBizCodeEnum, AppBizCodeEnum.ESD_LARGE_LOAN)) {
            List<String> reserve = CollUtils.newArrayList(
      "sesameCredit",
                "overdue",
                "btLimit",
                "hbLimit",
                "creditLimit",
                "providentFund",
                "loanAmount",
                "age",
                "realEstateInfo",
                "carInfo",
                "socialSecurity"
            );

            CollUtils.filter(list, t -> !Eq.strOr(t.getMappingName(), reserve));
        }

        //  信用贷
        if (Eq.enums(appBizCodeEnum, AppBizCodeEnum.ESD_CREDIT_LOAN)) {
            List<String> reserve = CollUtils.newArrayList(
      "career",
                "monthlySalary",
                "salaryPayMethod",
                "bizPubAccBankDetails",
                "bizLicenseYear",
                "bizBankDetails",
                "loanAmount",
                "providentFund",
                "socialSecurity"
            );
            CollUtils.filter(list, t -> !Eq.strOr(t.getMappingName(), reserve));
        }
        return list;
    }

}
